package com.example.test05;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import java.util.concurrent.ThreadPoolExecutor;

// 标记为服务类
@Service
public class TaskService {

    // 注入线程池（指定Bean名称）
    @Autowired
    @Qualifier("threadPool")
    private ThreadPoolExecutor threadPool;

    // 注入任务对象
    @Autowired
    private CountdownTask countdownTask;

    // 提交任务到线程池
    public void startTask() {
        System.out.println("=== 提交任务到线程池 ===");
        threadPool.submit(countdownTask);
    }
}
